/**
 * 
 */
package com.sys.object.common.context;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Component;

import com.sys.console.business.SysModuleService;
import com.sys.console.business.SysUserService;
import com.sys.console.mapper.SysUserLoginLogsMapper;
import com.sys.console.mapper.SysUserMonitorLogsMapper;




/**
 * @author 张喜朋
 *
 */
@Component
public class ServiceInitContainer {
	
	private static ServiceInitContainer serviceInstance=null;

	public static Map<String,Object> mapperMap = new HashMap<String,Object>();
	
	public static ServiceInitContainer getServiceInstance(){
//		if(serviceInstance==null)
//			serviceInstance = new ServiceInitContainer();
//		
//		mapperInit();
//		return serviceInstance;
		mapperInit();
		return ServiceInitContainerHolder.serviceInstance;
	}
	
	@PostConstruct
	public void init() throws Exception {
		mapperInit();
	}
	
	private static class ServiceInitContainerHolder{
		private final static ServiceInitContainer serviceInstance = new ServiceInitContainer();
	}
	
	private static void mapperInit(){
		if(mapperMap==null)
			mapperMap = new HashMap<String,Object>();
		
		mapperMap.put("sysUserService", ActiveConsoleBean.getBean("sysUserServiceImpl",SysUserService.class));
		mapperMap.put("sysUserLoginLogsMapper",  ActiveConsoleBean.getBean("sysUserLoginLogsMapper",SysUserLoginLogsMapper.class));//SysUserLoginLogsMapper sysUserLoginLogsMapper
		mapperMap.put("userMonitorLogsMapper", ActiveConsoleBean.getBean("sysUserMonitorLogsMapper",SysUserMonitorLogsMapper.class));
		mapperMap.put("sysModuleService", ActiveConsoleBean.getBean("sysModuleServiceImpl",SysModuleService.class));
		/********线程池***********/
		ExecutorService exec = Executors.newCachedThreadPool();
		mapperMap.put("executorService",exec);


	}
	
	@SuppressWarnings("unchecked")
	public static <T> T getBean(String beanName) {
		if(serviceInstance==null)
			ServiceInitContainer.getServiceInstance();
    	return (T) mapperMap.get(beanName);
    }


	public static void main(String[] args){

	}
}
